package test.study.async.reactor.mono.operator._3_combining.then;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import reactor.core.publisher.Mono;
import reactor.core.scheduler.Scheduler;
import reactor.core.scheduler.Schedulers;
import study.async.reactor.support.utils.SleepUtils;

/**
 * then 操作符的含义是等到上一个操作完成再进行下一个
 */
@Slf4j
public class _1_then_test {

    @Test
    public void test() {
        //
        Mono<String> mono = Mono.just("hello").then()
                .then(Mono.fromRunnable(() -> {
                    log.info("111111");
                })).then(Mono.fromCallable(() -> {
                    log.info("222222");
                    return "222222";
                })).subscribeOn(Schedulers.newSingle("ttt")).then(Mono.fromCallable(() -> {
                    log.info("333333");
                    return "333333";
                })).then(Mono.fromCallable(()-> {
                    log.info("444444");
                    return "44444";
                }));
        //
        mono.subscribe(e -> {
            log.info("[subscribe]: {}", e);
        });


//        SleepUtils.sleepFor(4);
    }
}
